package com.itheima.web;

import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.pojo.Spec;
import com.itheima.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/spec")
public class SpecController {

    @Autowired
    private SpecService specService;

    //    查询所有规格
    @GetMapping
    public Result findAll() {
        return this.specService.findAll();
    }

    //   添加规格参数
    @PostMapping
    public Result addSpec(@RequestBody Spec spec)
    {
        return this.specService.addSpec(spec);
    }

    //   分页查询规格参数
    @PostMapping("/search/{page}/{size}")
    public Result findByPage(@PathVariable("page") Integer currentPage, @PathVariable("size") Integer pageSize) {
        return this.specService.findByPage(currentPage,pageSize);
    }

    //   通过id查询
    @GetMapping("/{id}")
    public Result findById(Integer id) {
        return this.specService.findById(id);
    }

    //  通过id更新
    @PutMapping("/{id}")
    public Result updateById(Integer id,@RequestBody Spec spec) {
        return this.specService.updateById(id,spec);
    }

    //   通过id 删除
    @DeleteMapping("/{id}")
    public Result deleteById(Integer id) {
        return this.specService.deleteById(id);
    }
}
